#include "system.h"


void initTimer(void)
{
	//T1CON Register
	_TSIDL = 0; //Stop In Idle Mode
	_TGATE = 0;	//Gated Time Accumulation
	_TCKPS = 3;	//Prescale Value (2 bits)
	_TSYNC = 0;	//External Clock Synchronization
	_TCS   = 0;	//Internal/External Clock source

	PR1	   = 0x2222;	//Period Register Value

	_T1IF = 0;	//Interrupt Flag
	_T1IE = 1;	//Interrupt Enable

	_TON   = 1;	//Turns timer on or off


	// Timer 2/3
	T2CON = 0; // Reset Timer Controls
	T3CON = 0;
	TMR3 = 0;
	TMR2 = 0;
	T2CONbits.TCKPS = 3; // 256 Prescale value
	PR3 = 0xFFFF; // Period Registers
	PR2 = 0xFFFF;

	T2CONbits.T32 = 1;

	T2CONbits.TON = 0;

}

void __attribute__((__interrupt__, __shadow__, auto_psv)) _T1Interrupt(void)
{
	IRSTATE state;

	state = getIRState();

	if (state == PASSING)
	{
		LED4 = LED3;
		LED3 = ~LED3;
	}


	_T1IF = 0;
}
